// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 


import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JPanel;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYDotRenderer;
import org.jfree.data.function.NormalDistributionFunction2D;
import org.jfree.data.general.DatasetUtilities;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

public class NormalDistribution extends ApplicationFrame {

    private static final long serialVersionUID = 1L;

    public NormalDistribution(String s) {
     	
        super(s);
        
        EMAlgo.emRun();
        JPanel jpanel = createDemoPanel();
        jpanel.setPreferredSize(new Dimension(500, 270));
        setContentPane(jpanel);
    }

    public static JPanel createDemoPanel() {
        JFreeChart jfreechart = createChart();
        ChartPanel chartpanel = new ChartPanel(jfreechart);
        chartpanel.setMouseWheelEnabled(true);
        return chartpanel;
    }

    public static XYDataset createDatasetNormalDistributions() {
        XYSeriesCollection xyseriescollection = new XYSeriesCollection();
        NormalDistributionFunction2D normaldistributionfunction2d = new NormalDistributionFunction2D(EMAlgo.mueA, EMAlgo.sigmaA);
        org.jfree.data.xy.XYSeries xyseries = DatasetUtilities.sampleFunction2DToSeries(normaldistributionfunction2d, -40, 50D, 121, "Verteilung A");
        xyseriescollection.addSeries(xyseries);
        NormalDistributionFunction2D normaldistributionfunction2d1 = new NormalDistributionFunction2D(EMAlgo.mueB, EMAlgo.sigmaB);
        org.jfree.data.xy.XYSeries xyseries1 = DatasetUtilities.sampleFunction2DToSeries(normaldistributionfunction2d1, -40, 50D, 121, "Verteilung B");
        xyseriescollection.addSeries(xyseries1);
        
        return xyseriescollection;
    }
    
    public static XYDataset createDatasetDataPoints() {
        XYSeriesCollection xyseriescollection = new XYSeriesCollection();      
        
        XYSeries series = new XYSeries("Datenpunkte Verteilung A");
		XYSeries series2 = new XYSeries("Datenpunkte Verteilung B");
        
        for (Double key : EMAlgo.allData.keySet()) 
        {
        	if (EMAlgo.allData.get(key) < 0.5)
        		series.add(key, Double.valueOf(0.1));
        	else
        		series2.add(key, Double.valueOf(0.105));
		}
        
        xyseriescollection.addSeries(series2);
        xyseriescollection.addSeries(series);
        
        return xyseriescollection;
    }
    


    public static JFreeChart createChart() 
    {
        JFreeChart jfreechart = ChartFactory.createXYLineChart("EM Visualisierung", "X", "Y",createDatasetNormalDistributions(), PlotOrientation.VERTICAL, true, true, false);
        XYPlot xyplot = (XYPlot) jfreechart.getPlot();
        xyplot.setDataset(1, createDatasetDataPoints());
        
        XYDotRenderer renderer = new XYDotRenderer();
        renderer.setDotHeight(3);
        renderer.setDotWidth(3);
        renderer.setSeriesPaint(0, Color.RED);
        renderer.setSeriesPaint(1, Color.BLUE);
        xyplot.setRenderer(1,renderer);

        return jfreechart;
    }

    public static void main(String args[]) {
        NormalDistribution normaldistributiondemo2 = new NormalDistribution("JFreeChart: NormalDistributionDemo2.java");
        normaldistributiondemo2.pack();
        RefineryUtilities.centerFrameOnScreen(normaldistributiondemo2);
        normaldistributiondemo2.setVisible(true);
    }
}
